package com.tao.design.strategy.demo2;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Mi_Tao
 * @Date 2023/4/14
 * @Description 策略工厂来选择不同的支付方式（无状态）,支付方式是缓存到Map中
 * @Version 1.0
 **/
public class PaymentFactory {
    private static final Map<PaymentEnum, Payment> payStrategies = new HashMap<>();

    static {
        payStrategies.put(PaymentEnum.Ali,new AlipayPayment());
        payStrategies.put(PaymentEnum.Weixin,new WxPayment());
        payStrategies.put(PaymentEnum.Bank_Card,new BankCardPayment());
    }

    public static Payment getPayment(PaymentEnum payType) {
        if (payType == null) {
            throw new IllegalArgumentException("pay type is empty.");
        }
        if (!payStrategies.containsKey(payType)) {
            throw new IllegalArgumentException("pay type not supported.");
        }
        return payStrategies.get(payType);
    }

}

